


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="htmlId">
<head>
  <title>Coverage Report :: TelTime</title>
  <style type="text/css">
    @import "../../.css/coverage.css";
  </style>
</head>

<body>
<div class="header"></div>

<div class="content">
<div class="breadCrumbs">
    [ <a href="../../index.html">all classes</a> ]
    [ <a href="../index.html">com.edu.ctgu</a> ]
</div>

<h1>Coverage Summary for Class: TelTime (com.edu.ctgu)</h1>

<table class="coverageStats">
<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Class, %
</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">TelTime</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (1/ 1)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (4/ 4)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    67.4%
  </span>
  <span class="absValue">
    (29/ 43)
  </span>
</td>
</tr>

</table>

<br/>
<br/>


<div class="sourceCode"><i>1</i>&nbsp;package com.edu.ctgu;
<i>2</i>&nbsp;
<i>3</i>&nbsp;import java.text.ParseException;
<i>4</i>&nbsp;import java.text.SimpleDateFormat;
<i>5</i>&nbsp;import java.util.Calendar;
<i>6</i>&nbsp;import java.util.Date;
<i>7</i>&nbsp;
<i>8</i>&nbsp;public class TelTime {
<i>9</i>&nbsp;    public Date start;
<i>10</i>&nbsp;    public Date end;
<i>11</i>&nbsp;    private String startingTime;
<i>12</i>&nbsp;    private String endingTime;
<i>13</i>&nbsp;    private long total;//通话时长
<i>14</i>&nbsp;
<i>15</i>&nbsp;    public String DateFormate(Date date){
<b class="fc"><i>16</i>&nbsp;        SimpleDateFormat format = new SimpleDateFormat(&quot;yyyy-MM-dd HH:mm:ss E&quot;);</b>
<b class="fc"><i>17</i>&nbsp;        String sdate = format.format(date);</b>
<b class="fc"><i>18</i>&nbsp;        return sdate;</b>
<i>19</i>&nbsp;    }
<i>20</i>&nbsp;
<i>21</i>&nbsp;    public Date StrToDate(String str) {
<b class="fc"><i>22</i>&nbsp;        SimpleDateFormat format = new SimpleDateFormat(&quot;yyyyMMddHHmmss&quot;);</b>
<b class="fc"><i>23</i>&nbsp;        Date date = null;</b>
<i>24</i>&nbsp;        try {
<b class="fc"><i>25</i>&nbsp;            date = format.parse(str);</b>
<b class="nc"><i>26</i>&nbsp;        } catch (ParseException e) {</b>
<b class="nc"><i>27</i>&nbsp;            e.printStackTrace();</b>
<b class="fc"><i>28</i>&nbsp;        }</b>
<b class="fc"><i>29</i>&nbsp;        return date;</b>
<i>30</i>&nbsp;    }
<i>31</i>&nbsp;
<b class="fc"><i>32</i>&nbsp;    public  TelTime(String startingTime,String endingTime){</b>
<b class="fc"><i>33</i>&nbsp;        this.startingTime = startingTime;</b>
<b class="fc"><i>34</i>&nbsp;        this.endingTime = endingTime;</b>
<b class="fc"><i>35</i>&nbsp;        this.start = StrToDate(this.startingTime);</b>
<b class="fc"><i>36</i>&nbsp;        this.end = StrToDate(this.endingTime);</b>
<b class="fc"><i>37</i>&nbsp;    }</b>
<i>38</i>&nbsp;
<i>39</i>&nbsp;
<i>40</i>&nbsp;
<i>41</i>&nbsp;    public long getTelTime(){
<i>42</i>&nbsp;        long between;
<b class="fc"><i>43</i>&nbsp;        Calendar cal1 = Calendar.getInstance();</b>
<b class="fc"><i>44</i>&nbsp;        cal1.setTime(start);</b>
<b class="fc"><i>45</i>&nbsp;        Calendar cal2 = Calendar.getInstance();</b>
<b class="fc"><i>46</i>&nbsp;        cal2.setTime(end);</b>
<i>47</i>&nbsp;
<b class="fc"><i>48</i>&nbsp;        between = cal2.getTime().getTime()-cal1.getTime().getTime();</b>
<b class="fc"><i>49</i>&nbsp;        if(between&lt;0)</b>
<b class="nc"><i>50</i>&nbsp;            total =( (cal2.getTime().getTime()-cal1.getTime().getTime())/1000)/60;//得到通话时长</b>
<i>51</i>&nbsp;        else
<b class="fc"><i>52</i>&nbsp;            total = (between/1000+59)/60;</b>
<i>53</i>&nbsp;        //判断接通时间是否在发生转换的日期
<b class="fc"><i>54</i>&nbsp;        if((cal1.get(Calendar.MONTH) ==Calendar.MARCH &amp;&amp; cal1.get(Calendar.DATE) &gt;= 29 &amp;&amp; cal1.get(Calendar.DATE) &lt;= 31 &amp;&amp; cal1.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)</b>
<b class="fc"><i>55</i>&nbsp;                || ((cal1.get(Calendar.MONTH) ==Calendar.APRIL &amp;&amp; cal1.get(Calendar.DATE) &gt;= 1 &amp;&amp; cal1.get(Calendar.DATE) &lt;= 4 &amp;&amp; cal1.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)))</b>
<i>56</i>&nbsp;        {
<b class="fc"><i>57</i>&nbsp;            System.out.println(&quot;需要转换1&quot;);</b>
<b class="fc"><i>58</i>&nbsp;            if(cal1.get(Calendar.HOUR_OF_DAY)&lt;2 &amp;&amp; cal2.get(Calendar.HOUR_OF_DAY)&gt;=3)</b>
<b class="nc"><i>59</i>&nbsp;                total -=60;//时间从2点转换到3点减去1h</b>
<i>60</i>&nbsp;        }else{
<b class="nc"><i>61</i>&nbsp;            if((cal2.get(Calendar.MONTH) ==3 &amp;&amp; cal2.get(Calendar.DATE) &gt;= 29 &amp;&amp; cal2.get(Calendar.DATE) &lt;= 31 &amp;&amp; cal2.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)</b>
<b class="nc"><i>62</i>&nbsp;                    || ((cal2.get(Calendar.MONTH) ==4 &amp;&amp; cal2.get(Calendar.DATE) &gt;= 1 &amp;&amp; cal2.get(Calendar.DATE) &lt;= 4 &amp;&amp; cal2.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)))</b>
<i>63</i>&nbsp;            //判断结束时间是否在转换的日期
<i>64</i>&nbsp;            {
<b class="nc"><i>65</i>&nbsp;                if(cal2.get(Calendar.HOUR_OF_DAY)&gt;3 )</b>
<b class="nc"><i>66</i>&nbsp;                    total -=60;</b>
<i>67</i>&nbsp;            }
<i>68</i>&nbsp;        }
<i>69</i>&nbsp;
<b class="fc"><i>70</i>&nbsp;        if(cal1.get(Calendar.MONTH) ==Calendar.OCTOBER &amp;&amp; cal1.get(Calendar.DATE) &gt;= 25 &amp;&amp; cal1.get(Calendar.DATE) &lt;= 31 &amp;&amp; cal1.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)</b>
<i>71</i>&nbsp;        {
<b class="nc"><i>72</i>&nbsp;            if(cal1.get(Calendar.HOUR_OF_DAY) ==2){</b>
<b class="nc"><i>73</i>&nbsp;                total +=60;</b>
<i>74</i>&nbsp;            }
<i>75</i>&nbsp;        }else{
<b class="fc"><i>76</i>&nbsp;            if(cal2.get(Calendar.MONTH) ==Calendar.OCTOBER &amp;&amp; cal2.get(Calendar.DATE) &gt;= 25 &amp;&amp; cal2.get(Calendar.DATE) &lt;= 31 &amp;&amp; cal2.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)</b>
<i>77</i>&nbsp;            {
<b class="nc"><i>78</i>&nbsp;                if(cal2.get(Calendar.HOUR_OF_DAY)==2)</b>
<i>79</i>&nbsp;                {
<b class="nc"><i>80</i>&nbsp;                    total +=60;</b>
<i>81</i>&nbsp;                }
<i>82</i>&nbsp;            }
<i>83</i>&nbsp;        }
<b class="fc"><i>84</i>&nbsp;        if(total&gt;1800 || total &lt;0){</b>
<b class="nc"><i>85</i>&nbsp;            System.out.println(&quot;错误!!!时限范围出错!!!&quot;);</b>
<b class="nc"><i>86</i>&nbsp;            return 0;</b>
<i>87</i>&nbsp;        }else{
<i>88</i>&nbsp;            //System.out.println(&quot;间隔正确&quot;);
<b class="fc"><i>89</i>&nbsp;            return total;</b>
<i>90</i>&nbsp;        }
<i>91</i>&nbsp;    }
<i>92</i>&nbsp;}
</div>
</div>

<div class="footer">
    
    <div style="float:right;">generated on 2022-04-03 15:03</div>
</div>
</body>
</html>
